package com.scalar.chiptrack.finance.actions;

import com.scalar.chiptrack.ChipTrackAction;
import com.scalar.chiptrack.sales.dao.NewCustomerDAO;
import com.scalar.chiptrack.operations.process.dao.NewProductDAO;
import com.scalar.chiptrack.commons.SessionKeys;
import com.scalar.chiptrack.commons.Constants;
import com.scalar.chiptrack.users.User;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionForm;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.ArrayList;

/**
 * Created by IntelliJ IDEA.
 * User: Administrator
 * Date: May 28, 2007
 * Time: 11:59:16 AM
 * To change this template use File | Settings | File Templates.
 */
public class CreditDebitNoteReportAction extends ChipTrackAction
{
    private static final String ACTION_NAME = "/creditDeditNoteReport.do";
    public ActionForward execute( ActionMapping mapping,
                                  ActionForm form,
                                  HttpServletRequest request,
                                  HttpServletResponse response )
            throws Exception
    {

        String action = request.getParameter( "action" );
        HttpSession session = request.getSession();

        User user = ( User ) session.getAttribute( SessionKeys.USER_KEY );

        if( user == null )
        {
            session.setAttribute( SessionKeys.SOURCE_PAGE_KEY, ACTION_NAME + "?" + request.getQueryString() );
            return ( mapping.findForward( "login" ) );
        }

        //ProductDetailsReportForm productDetailsReportForm = ( ProductDetailsReportForm ) form;
        ArrayList productList   = null;
        ArrayList customerList   = null;
        ArrayList liTypeList = null;
        ArrayList statusList = null;
       
       
        if ( action == null )
        {
            action = "";
        }
        try
        {
            if ( "creditDeditNoteReport".equalsIgnoreCase(action) || "".equals(action) )
            {
                try
                {
                    productList =  NewProductDAO.loadPartNumbers( null,1,Constants.LOCATION_TYPE_FG,true,true,false,0);
                    customerList = NewCustomerDAO.getAllCustomerNamesByCustomerType( "Customer" );

                }
                catch( Exception e )
                {
                    productList     = new ArrayList();
                    customerList    = new ArrayList();
                   /* liTypeList      = new ArrayList();
                    statusList      = new ArrayList();*/

                    e.printStackTrace();
                }
                request.setAttribute( "productList", productList );
                request.setAttribute( "customerList", customerList );
                /*request.setAttribute( "packageTypeList", packageTypeList );
                request.setAttribute( "pinCountList", pinCountList );
                request.setAttribute( "productGroupList", productGroupList );*/

            }
        }
        catch ( Exception e)
        {
            //errors.put ( "Could not generate excel file", null );
            e.printStackTrace();
        }

        if( "creditDeditNoteReport".equalsIgnoreCase(action) )
        {
            return ( mapping.findForward( "creditDeditNoteReport" ) );
        }
        else
        {
            return null;
        }
    }
}
